package com.qm.console.component.util;

import java.text.DecimalFormat;
import java.util.Random;
import java.util.UUID;

public class GeneratorUtils {

    public static final int VERIFY_CODE_LENGTH = 4;

    /**
     * 生成指定长度的数字验证码
     * @param codeLength
     * @return
     */
    public static String genDigitCode(int codeLength) {

        Random random = new Random();

        int bound = (int)Math.pow(10, codeLength);
        int code = random.nextInt(bound);
        DecimalFormat df = new DecimalFormat("0000");
        return df.format(code);
    }

    /**
     * 生成长度为4的数字验证码
     * @return
     */
    public static String genDigitCode() {
        return genDigitCode(VERIFY_CODE_LENGTH);
    }

    /**
     * 生成UUID字符串
     * @return
     */
    public static String genUUIDString() {
        String uuid = UUID.randomUUID().toString();
        return uuid.replaceAll("-", "");
    }

    public static void main(String[] args) {
        System.out.println(genUUIDString());
    }
}
